<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/css/public.css" media="all">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/css/wp.css" media="all">

    <style>

        .input-block{
            margin-right: 70px;
        }

        .unit{
            position: absolute;
            right: 0px;
            top: 0px;
            right: -30px;
            line-height: 40px;
        }

        .layui-tab-brief>.layui-tab-title .layui-this{
            color: #000000;
            font-size: 18px;
            font-weight: bold;
        }

        .tab-title{
            color: #000000;
            font-size: 18px !important;
            font-weight: bold;
        }

        .layui-tab-brief>.layui-tab-more li.layui-this:after, .layui-tab-brief>.layui-tab-title .layui-this:after{
            border-bottom: 2px solid #1890FF;
        }

    </style>
</head>
<body>
<div id="container" class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-tab layui-tab-brief wp-module-box" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title" style="text-align: center;">
                <li class="layui-this tab-title">手续费配置</li>
                <li class="tab-title">融资轮次兑换配置</li>
                <li class="tab-title">归集阈值配置</li>
                <li class="tab-title">系统参考价格</li>
            </ul>
            <div class="layui-tab-content" style="height: auto;padding-top: 30px;">
                <div class="layui-tab-item layui-show">
                    <form id="feeForm" class="layui-form" >
                        <div class="layui-form-item">
                            <label class="layui-form-label">转账手续费</label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="transFee" maxlength="5" oninput="this.value=this.value.replace(/[^\-?\d.]/g,'');" lay-verify="feeCheck" autocomplete="off" class="layui-input">
                                <div class="unit">%</div>
                            </div>
                            <div class="layui-form-mid layui-word-aux" style="left: 110px;">
                                <span class="layui-badge-dot layui-bg-green"></span>
                                用户A向用户B转出SHQC所收取的手续费
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">提币手续费</label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="mentionFee" maxlength="5" oninput="this.value=this.value.replace(/[^\-?\d.]/g,'');" lay-verify="feeCheck" autocomplete="off" class="layui-input">
                                <div class="unit">%</div>
                            </div>
                            <div class="layui-form-mid layui-word-aux" style="left: 110px;">
                                <span class="layui-badge-dot layui-bg-green"></span>
                                用户将SHQC提出到区块链上收取的手续费
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin: auto;text-align: center;">
                                <button type="submit" style="width: 120px;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="fee-submit-btn">提交</button>
                                <button type="button" style="width: 120px;" class="layui-btn layui-btn-normal" lay-filter="fee-reset-btn" @click="reset('feeForm')">重置</button>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="layui-tab-item">
                    <form id="exchangeForm" class="layui-form" >
                        <div class="layui-form-item" style="margin-bottom: 0px;">
                            <label class="layui-form-label" style="font-size: 18px;position: relative;left: -8px;">天使轮</label>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">1 USDT = </label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="tslUnit" maxlength="10" oninput="this.value=this.value.replace(/\D/g,'');" lay-verify="exchangeCheck" autocomplete="off" class="layui-input">
                                <div class="unit" style="right: -50px;">SHQC</div>
                            </div>
                        </div>

                        <div class="layui-form-item" style="margin-bottom: 0px;">
                            <label class="layui-form-label" style="font-size: 18px;position: relative;left: -8px;">基石轮</label>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">1 USDT = </label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="jslUnit" maxlength="10" oninput="this.value=this.value.replace(/\D/g,'');" lay-verify="exchangeCheck" autocomplete="off" class="layui-input">
                                <div class="unit" style="right: -50px;">SHQC</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin: auto;text-align: center;">
                                <button type="submit" style="width: 120px;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="exchange-submit-btn">提交</button>
                                <button type="button" style="width: 120px;" class="layui-btn layui-btn-normal" lay-filter="exchange-reset-btn" @click="reset('exchangeForm')">重置</button>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="layui-tab-item">
                    <form id="collectForm" class="layui-form">
                        <div class="layui-form-item">

                            <label class="layui-form-label" >USDT归集阈值</label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="collectThresholdUsdt" maxlength="10" oninput="this.value=this.value.replace(/\D/g,'');" lay-verify="collectCheck" autocomplete="off" class="layui-input">
                                <div class="unit" style="right: -50px;">USDT</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">SHQC归集阈值</label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="collectThresholdShqc" maxlength="10" oninput="this.value=this.value.replace(/\D/g,'');" lay-verify="collectCheck" autocomplete="off" class="layui-input">
                                <div class="unit" style="right: -50px;">SHQC</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin: auto;text-align: center;">
                                <button type="submit" style="width: 120px;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="collect-submit-btn">提交</button>
                                <button type="button" style="width: 120px;" class="layui-btn layui-btn-normal" lay-filter="collect-reset-btn" @click="reset('collectForm')">重置</button>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="layui-tab-item">
                    <form id="systemPriceForm" class="layui-form">
                        <div class="layui-form-item">

                            <label class="layui-form-label" >系统参考价格</label>
                            <div class="layui-input-block input-block">
                                <input type="text" v-model="systemPriceUSDT" maxlength="10" oninput="this.value=this.value.replace(/\D/g,'');" lay-verify="systemPriceCheck" autocomplete="off" class="layui-input">
                                <div class="unit" style="right: -50px;">USDT</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin: auto;text-align: center;">
                                <button type="submit" style="width: 120px;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="systemPrice-submit-btn">提交</button>
                                <button type="button" style="width: 120px;" class="layui-btn layui-btn-normal" lay-filter="systemPrice-reset-btn" @click="reset('systemPriceForm')">重置</button>
                            </div>
                        </div>
                    </form>
                </div>


            </div>
        </div>

    </div>
</div>

<script src="/wpui-admin/wp-ewallet-admin/static/js/jquery-3.4.1.min.js"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/lib/layui/layui.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/module/index/config.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/js/vue.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/js/vue-i18n.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp-i18n.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp-project.js" charset="utf-8"></script>
<script>

    /*<!--限制文本框只能输入正数-->
    <input type="text" οnkeyup="this.value=this.value.replace(/\D/g,'')"/>

    <!--限制文本框只能输入正数、小数-->
    <input type="text" οnkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>

    <!--限制文本框只能输入正数、小数、负数-->
    <input type="text" οnkeyup="this.value=this.value.replace(/[^\-?\d.]/g,'')"/>*/


    layui.use(['form','element'], function () {
        var $ = layui.jquery,
            form = layui.form;

        var vm = new Vue({
            el: '#container',
            i18n: wp.i18n(),
            data:{
                // 初始默认值
                initValue:{
                    // 提币手续费
                    transFee:'',
                    // 转账手续费
                    mentionFee:'',

                    // 天使轮兑换值
                    tslUnit:'',
                    // 基石轮兑换值
                    jslUnit:'',


                    //归集阈值USDT
                    collectThresholdUsdt:'',
                    //归集阈值SHQC
                    collectThresholdShqc:'',

                    systemPriceUSDT:''
                },

                // 提币手续费
                transFee:'',
                // 转账手续费
                mentionFee:'',

                // 天使轮兑换值
                tslUnit:'',
                // 基石轮兑换值
                jslUnit:'',

                // 归集阈值
                collectThresholdUsdt:'',
                // 归集频次
                collectThresholdShqc:'',

                systemPriceUSDT:'',

                mapping:{
                    'trans_fee':'transFee',
                    'mention_fee':'mentionFee',
                    'max_value':'collectThresholdUsdt',
                    'max_value_shqc':'collectThresholdShqc',
                    '1000':'tslUnit',
                    '2000':'jslUnit',
                    'system_price':'systemPriceUSDT'
                }
            },
            mounted:function(){
                var that = this;
                this.init('1000',function(itemList){
                    for(var i = 0; i < itemList.length; i++){
                        var item = itemList[i];
                        // 乘以100
                        that[that.mapping[item.itemCode]] = item.itemValue * 100;
                        that.initValue[that.mapping[item.itemCode]] = item.itemValue * 100;
                    }
                });

                this.init('1001',function(itemList){
                    for(var i = 0; i < itemList.length; i++){
                        var item = itemList[i];
                        that[that.mapping[item.itemCode]] = item.itemValue;
                        that.initValue[that.mapping[item.itemCode]] = item.itemValue;
                    }
                });

                this.init('1006',function(itemList){
                    for(var i = 0; i < itemList.length; i++){
                        var item = itemList[i];
                        that[that.mapping[item.itemCode]] = item.itemValue;
                        that.initValue[that.mapping[item.itemCode]] = item.itemValue;
                    }
                });

                this.getExchangeMoneyRatio(function(itemList){
                    for(var i = 0; i < itemList.length; i++){
                        var item = itemList[i];
                        that[that.mapping[item.converType]] = item.exchangeRate ? item.exchangeRate.split(':')[1] : '';
                        that.initValue[that.mapping[item.converType]] = item.exchangeRate ? item.exchangeRate.split(':')[1] : '';
                    }
                });

                this.submitEvent();
            },
            methods: {
                init:function(dicId,callback){
                    wp.httpGet({
                        url:wp.url('/wp/ewallet/common/pubTypeDict/getPubItemDict'),
                        data:{
                            dicId: dicId
                        },
                        success:function(data){
                            var itemList = data.dataBody;
                            if(itemList){
                                callback(itemList);
                            }
                        }
                    });

                },
                getExchangeMoneyRatio: function(callback){
                    wp.httpGet({
                        url:wp.url('/wp/ewallet/common/converRoleDict/getExchangeMoneyRatio'),
                        success:function(data){
                            var itemList = data.dataBody;
                            if(itemList){
                                callback(itemList);
                            }
                        }
                    });
                },
                submitEvent:function(){
                    var reg = /^(\-)?\d+(\.\d+)?$/;

                    var that = this;
                    // 需要的时候自定义验证规则
                    form.verify({
                        feeCheck: function(value){
                            if(!value){
                                return '不能为空';
                            }

                            if(!reg.test(value)){
                                return '参数格式不正确';
                            }
                        },

                        exchangeCheck: function(value){
                            if(!value){
                                return '不能为空';
                            }
                        },

                        collectCheck: function(value){
                            if(!value){
                                return '不能为空';
                            }
                        },

                        systemPriceCheck: function(value){
                            if(!value){
                                return '不能为空';
                            }
                        }

                    });

                    // 费用提交
                    form.on('submit(fee-submit-btn)', function (data) {
                        var result = JSON.stringify(data.field);
                        var loading = wp.loading();
                        wp.httpPost({
                            url:wp.url('/wp/ewallet/common/pubTypeDict/modifyHandlingFee'),
                            data:{
                                transFee:that.transFee,
                                mentionFee:that.mentionFee
                            },
                            success:function(data){
                                layer.msg('修改成功');
                                wp.closeLoading();
                            }
                        });
                        return false;
                    });

                    // 融资轮次兑换
                    form.on('submit(exchange-submit-btn)', function (data) {
                        var result = JSON.stringify(data.field);
                        var array = new Array();
                        array.push({
                            baseMoney:'1000',//USDT
                            priceMoney: '2000',//SHQC
                            converType: '1000',//天使轮
                            exchangeRate: 1 + ":" + that.tslUnit
                        });

                        array.push({
                            baseMoney:'1000',
                            priceMoney: '2000',
                            converType: '2000',//基石轮
                            exchangeRate: 1 + ":" + that.jslUnit
                        });

                        var loading = wp.loading();
                        wp.httpPost({
                            url:wp.url('/wp/ewallet/common/converRoleDict/exchangeMoneyRatioSetting'),
                            data:{
                                params : JSON.stringify(array)
                            },
                            success:function(data){
                                layer.msg('修改成功');
                                wp.closeLoading();
                            }
                        });
                        return false;
                    });


                    // 归集阈值
                    form.on('submit(collect-submit-btn)', function (data) {
                        var result = JSON.stringify(data.field);
                        var array = new Array();
                        array.push({
                            itemCode:'max_value',
                            itemValue:that.collectThresholdUsdt
                        });

                        array.push({
                            itemCode:'max_value_shqc',
                            itemValue:that.collectThresholdShqc
                        });

                        var loading = wp.loading();
                        wp.httpPost({
                            url:wp.url('/wp/ewallet/common/pubTypeDict/modifyItemValueByItemCode'),
                            data:{
                                json : JSON.stringify(array)
                            },
                            success:function(data){
                                layer.msg('修改成功');
                                wp.closeLoading();
                            }
                        });
                        return false;
                    });

                    // 系统参考价配置
                    form.on('submit(systemPrice-submit-btn)', function (data) {
                        var result = JSON.stringify(data.field);
                        var array = [];
                        array.push({
                            itemCode:'system_price',
                            itemValue:that.systemPriceUSDT
                        });

                        var loading = wp.loading();
                        wp.httpPost({
                            url:wp.url('/wp/ewallet/common/pubTypeDict/modifyItemValueByItemCode'),
                            data:{
                                json : JSON.stringify(array)
                            },
                            success:function(data){
                                layer.msg('设置成功');
                                wp.closeLoading();
                            }
                        });
                        return false;
                    });


                },
                reset:function(form){
                    var that = this;
                    $("#" + form).get(0).reset();

                    if(form == 'feeForm'){
                        that.transFee = that.initValue.transFee;
                        that.mentionFee = that.initValue.mentionFee;
                    }

                    if(form == 'exchangeForm'){
                        that.tslUnit = that.initValue.tslUnit;
                        that.jslUnit = that.initValue.jslUnit;
                    }

                    if(form == 'collectForm'){
                        that.collectThresholdUsdt = that.initValue.collectThresholdUsdt;
                        that.collectThresholdShqc = that.initValue.collectThresholdShqc;
                    }

                    if(form == 'systemPriceForm'){
                        that.systemPriceUSDT = that.initValue.systemPriceUSDT;
                    }

                }
            }
        });
    });
</script>

</body>
</html>